package cn.hdu.community.service.serviceImpl;

import cn.hdu.community.entity.User;
import cn.hdu.community.mapper.UserMapper;
import cn.hdu.community.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangxin
 * @since 2022-04-01
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public User findUserByEmail(String userEmail) {
        return userMapper.findUserByEmail(userEmail);
    }

    @Override
    public Boolean existsUserByEmail(String userEmail) {
        return userMapper.existsUserByEmail(userEmail) > 0;
    }

    @Override
    public Boolean insertUser(String userEmail, String userPassword) {
        User user = new User();
        user.setUserEmail(userEmail);
        user.setUserPassword(userPassword);
        userMapper.insert(user);
        return userMapper.existsUserByEmail(userEmail) > 0;
    }

    @Override
    public void insertUserActivityTime(Integer userId, LocalDate userActivityTime) {
        User user = new User();
        user.setUserId(userId);
        user.setUserActivityTime(userActivityTime);
        userMapper.updateById(user);
    }

}
